﻿#include "ReadWindow.h"
#include <QFileDialog>

ReadWindow::ReadWindow(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);
}

ReadWindow::~ReadWindow()
{
}

void ReadWindow::closeEvent(QCloseEvent* e)
{
    this->deleteLater();
}

// 选择文件
void ReadWindow::on_file_clicked()
{
    // 文件选择框
    QFileDialog* fileDialog = new QFileDialog(this);
    fileDialog->setNameFilter(tr("*.mp4"));
    fileDialog->setWindowTitle(tr("Open MP4"));
    fileDialog->exec();

    QStringList qstrList = fileDialog->selectedFiles();

    if (qstrList.isEmpty())
    {
        return;
    }

    QString picturePath = qstrList[0];
    _mp4Decoder.open(picturePath.toStdString());
    _aacDecoder.open();
}

// 开始预览
void ReadWindow::on_start_clicked()
{
    Mp4DecoderData audioData;
    _mp4Decoder.readAudio(&audioData);
    _aacDecoder.decode((char*)audioData.sampleData, audioData.sampleSize, nullptr);
}

// 停止预览
void ReadWindow::on_stop_clicked()
{
    _mp4Decoder.close();
    _aacDecoder.close();
}
